﻿<c:BaseControl x:Class="personalplaner.gui.stamm.views.DienstStamm"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:bs="clr-namespace:personalplaner.business.stamm;assembly=personalplaner.business"
        xmlns:vm="clr-namespace:personalplaner.common.mvvm.factory;assembly=personalplaner.common"
        xmlns:fac="clr-namespace:personalplaner.gui.stamm.viewmodels.factories"
        vm:ViewModelLoader.FactoryType="{x:Type fac:DienstStammModelFactory}"
        xmlns:c="clr-namespace:personalplaner.common.controls;assembly=personalplaner.common"
             xmlns:conv="clr-namespace:personalplaner.common.converters;assembly=personalplaner.common"
             xmlns:local="clr-namespace:personalplaner.gui.stamm.views"
             xmlns:p="clr-namespace:personalplaner.gui.Properties"
             Name="baseControl"
             Foreground="#E1000000">

    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/personalplaner.common;component/resources/CommonStyles.xaml"/>
                <ResourceDictionary Source="/personalplaner.common;component/resources/styles/WhiteStyleTemplates.xaml"/>

                <ResourceDictionary>
                    <conv:ColorToSolidColorBrushConverter x:Key="colorToBrush"/>
                </ResourceDictionary>
                
            </ResourceDictionary.MergedDictionaries>            
        </ResourceDictionary>
    </Control.Resources>
    
    <Grid >

        <Grid.Resources>
            <DataTemplate DataType="{x:Type bs:Dienst}">
                <Grid><!--Margin="0,0,20,0"-->

                    <Grid.ToolTip>
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding Name}" />
                            <TextBlock Text="/" Margin="5,0,5,0" Grid.Column="1"/>
                            <TextBlock Text="{Binding KurzText}" Grid.Column="2"/>
                            <Border Width="15" Height="13" Background="{Binding Color, Converter={StaticResource colorToBrush}}" Grid.Column="3" Margin="5,0,0,-3" />
                        </Grid>
                    </Grid.ToolTip>
                    
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="60"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    
                    <Grid.OpacityMask>
                        <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                            <GradientStop Offset="0.0" Color="Black" />
                            <GradientStop Offset="0.8" Color="Black" />
                            <GradientStop Offset="1.0" Color="Transparent" />
                        </LinearGradientBrush>
                    </Grid.OpacityMask>

                    <!-- Create a trasparent border that keeps the width static -->
                    <Border Background="Transparent" Width="250" Grid.ColumnSpan="2"/>
                    
                    <TextBlock x:Name="name" Text="{Binding Name}" Foreground="{Binding Color, Converter={StaticResource colorToBrush}}" />
                    <TextBlock x:Name="kurztext" Text="{Binding KurzText}" Foreground="{Binding Color, Converter={StaticResource colorToBrush}}" Grid.Column="1"/>

                </Grid>

                <DataTemplate.Triggers>
                    <DataTrigger Binding="{Binding Color}" Value="{x:Null}">
                        <Setter TargetName="name" Property="Foreground" Value="Black"/>
                        <Setter TargetName="kurztext" Property="Foreground" Value="Black"/>
                    </DataTrigger>
                </DataTemplate.Triggers>
                
            </DataTemplate>
            
            <conv:ColorToSolidColorBrushConverter x:Key="colorToBrush"/>
            
            <conv:DateTimeToIsoConverter x:Key="dateConverter"/>
            
        </Grid.Resources>
    
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <!--<ColumnDefinition MaxWidth="500" Width="Auto"/>-->
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <ListBox ItemsSource="{Binding Dienste}" SelectedItem="{Binding SelectedDienst}" Margin="10,10,0,0" ScrollViewer.HorizontalScrollBarVisibility="Disabled"/>

        <GridSplitter Width="4" Background="Transparent"/>
        
        <GroupBox Margin="0,5,5,0" Grid.Column="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="70"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="130"/>
                    <ColumnDefinition Width="400"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>

                <TextBlock VerticalAlignment="Center" Text="Name"/>
                <TextBox Grid.Column="1" Margin="2"
                         IsEnabled="{Binding DataContext.IsEditEnabled, ElementName=baseControl}"
                         DataContext="{Binding SelectedDienst}" 
                         Text="{FocusBinding Path=Name, ValidatesOnDataErrors=True}"/>

                <TextBlock VerticalAlignment="Center" Grid.Row="1" Text="Kurztext"/>
                <TextBox Grid.Column="1" Margin="2" Grid.Row="1"
                         IsEnabled="{Binding DataContext.IsEditEnabled, ElementName=baseControl}"
                         DataContext="{Binding SelectedDienst}" 
                         Text="{FocusBinding Path=KurzText, ValidatesOnDataErrors=True}"/>

                <TextBlock VerticalAlignment="Top" Grid.Row="2" Text="Beschreibung" />
                <TextBox Grid.Column="1" Grid.Row="2" AcceptsReturn="True" TextWrapping="Wrap" Margin="2" 
                         IsEnabled="{Binding DataContext.IsEditEnabled, ElementName=baseControl}"
                         DataContext="{Binding SelectedDienst}" 
                         Text="{FocusBinding Path=LangText, ValidatesOnDataErrors=True}"/>

                <TextBlock Grid.Row="3" Text="Im Saldo mitrechnen"/>
                <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal">
                    <CheckBox Margin="2,3,2,3"
                          IsEnabled="{Binding DataContext.IsEditEnabled, ElementName=baseControl}"
                          DataContext="{Binding SelectedDienst, ValidatesOnDataErrors=True}" 
                          IsChecked="{Binding IsGerechnet}"/>
                    <Image Source="/personalplaner.gui;component/resources/images/Info.png" Height="16" Width="16" ToolTip="{x:Static p:Resources.DienstImSaldoRechnenToolTip}"/>
                </StackPanel>

                <TextBlock Grid.Row="4" Text="Diensttyp"/>
                <ComboBox Grid.Row="4" Grid.Column="1" Margin="2,3,2,3" IsEnabled="{Binding DataContext.IsEditEnabled, ElementName=baseControl}"
                          ItemsSource="{Binding DienstTypen}"
                          SelectedValue="{Binding SelectedDienst.Typ}"
                          SelectedValuePath="Wert"
                          DisplayMemberPath="Text"/>

                <TextBlock Grid.Row="5" Text="Farbe"/>
                <StackPanel Grid.Row="5" Grid.Column="1" Orientation="Horizontal" DataContext="{Binding SelectedDienst}">
                    <!--<Border BorderBrush="Black" BorderThickness="1" Height="20" Width="20" Margin="2,0,10,0" Background="{Binding Color, Converter={StaticResource colorToBrush}}"/>-->
                    <c:ColorPicker Width="100" Margin="0,0,10,0" SelectedColor="{Binding Color}"/>
                    <Image Source="/personalplaner.gui;component/resources/images/Info.png" Height="16" Width="16" ToolTip="{x:Static p:Resources.DienstNameColorToolTip}"/>
                </StackPanel>
                
                <GroupBox Grid.Row="6" Header="Zeiten" Grid.ColumnSpan="3" BorderThickness="0" Margin="0,10,40,0" ScrollViewer.HorizontalScrollBarVisibility="Auto">
                    <GroupBox.Resources>
                        
                        <DataTemplate DataType="{x:Type bs:DienstZeit}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="70"/>
                                    <ColumnDefinition Width="70"/>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                
                                
                                
                                <TextBlock Text="{Binding Von}" Grid.Column="0" Margin="0,0,0,0" FontWeight="Normal"/>
                                <TextBlock Text="{Binding Bis}" Grid.Column="1" Margin="0,0,0,0" FontWeight="Normal"/>
                                <TextBlock Text="{Binding Zeit}" Grid.Column="2" Margin="0,0,0,0" FontWeight="Normal"/>
                                
                                <TextBlock Text="{Binding ZeitEinheitTyp}" Grid.Column="3" Margin="0,0,0,0" FontWeight="Normal"/>

                                

                                <!--<Button  HorizontalAlignment="Left" Grid.Column="3" Style="{StaticResource TransparentButtonStyle}" Margin="17,0,0,0" Cursor="Hand"
                                         Command="{Binding DataContext.DeleteTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DienstStamm}}}" CommandParameter="{Binding}">
                                    <Path Data="M 0,4 L 8,4" StrokeThickness="3" Stroke="Red" VerticalAlignment="Center"/>
                                </Button>-->
                                
                            </Grid>
                        </DataTemplate>
                        
                        <DataTemplate DataType="{x:Type bs:DienstZeitCollection}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="100"/>
                                    <ColumnDefinition Width="85"/>
                                    <ColumnDefinition Width="70"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>

                                <Button Style="{StaticResource TransparentButtonStyle}" HorizontalAlignment="Left" Cursor="Hand"
                                        Command="{Binding DataContext.CollapseTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DienstStamm}}}" CommandParameter="{Binding}" >
                                    <Border BorderBrush="Black" BorderThickness="1" CornerRadius="1" Background="Transparent" Width="12" Height="12" Padding="1">
                                        <Path Data="M 0,4 L 8,4 M 4,0 L 4,8" StrokeThickness="2" Stroke="Black" x:Name="buttonPath" SnapsToDevicePixels="True" Width="8" Height="8"/>
                                    </Border>
                                </Button>

                                <TextBlock Text="{Binding DatumVon, Mode=OneWay, Converter={StaticResource dateConverter}}" Grid.Column="1" Margin="10,0,10,0" FontWeight="SemiBold"/>
                                <TextBlock Text="{Binding DatumBis, Mode=OneWay, Converter={StaticResource dateConverter}}" Grid.Column="2" Margin="10,0,10,0" FontWeight="SemiBold"/>
                                
                                
                                <!--summe der zeiten anzeigen-->
                                <TextBlock Text="{Binding ZeitTotal}" Grid.Column="3" FontWeight="SemiBold" Name="txtZeit"/>
                                
                                <CheckBox IsChecked="{Binding IsAbteilungsZeit, Mode=OneWay}" Grid.Column="4" Margin="10,0,10,0" IsHitTestVisible="False"/>

                                <!--Style="{StaticResource TransparentButtonStyle}"-->
                                <Button  HorizontalAlignment="Left" Grid.Column="6" Margin="120,0,0,0" Cursor="Hand" VerticalAlignment="Center" Width="16" Height="16"
                                         Command="{Binding DataContext.RemoveBereichCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DienstStamm}}}" CommandParameter="{Binding}" ToolTip="{x:Static p:Resources.DienstZeitEntfernen}">
                                    <Path Data="M 0,4 L 8,4" StrokeThickness="3" Stroke="Red" VerticalAlignment="Center" Height="8" HorizontalAlignment="Center"/>
                                </Button>
                                <!--Style="{StaticResource TransparentButtonStyle}"-->
                                <Button HorizontalAlignment="Left" Grid.Column="7"  Margin="10,0,0,0" Cursor="Hand" VerticalAlignment="Center" Width="16" Height="16"
                                        Command="{Binding DataContext.EditTimeCommand, RelativeSource={RelativeSource AncestorType={x:Type local:DienstStamm}}}" CommandParameter="{Binding}" ToolTip="{x:Static p:Resources.DienstZeitBearbeiten}">
                                    <Image Source="/personalplaner.gui;component/resources/images/Edit.png" Height="12"/>
                                </Button>


                                <Grid Grid.Row="1" Grid.ColumnSpan="7" Visibility="Collapsed" x:Name="timesContainer">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="110"/>
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="Detail" Margin="40,0,0,0" HorizontalAlignment="Left" FontWeight="Medium" VerticalAlignment="Top" />
                                    <ItemsControl ItemsSource="{Binding}" Grid.Column="1" Margin="5,0,0,20"/>
                                </Grid>
                                
                                
                            </Grid>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding IsExpanded}" Value="True">
                                    <Setter TargetName="buttonPath" Property="Data" Value="M 0,4 L 8,4"/>
                                    <Setter TargetName="timesContainer" Property="Visibility" Value="Visible"/>
                                </DataTrigger>
                                <DataTrigger Binding="{Binding IsAbteilungsZeit}" Value="true">
                                    <Setter TargetName="buttonPath" Property="Visibility" Value="Collapsed"/>
                                    <Setter TargetName="txtZeit" Property="Visibility" Value="Collapsed"/>
                                </DataTrigger>
                            </DataTemplate.Triggers>
                            
                        </DataTemplate>
                    </GroupBox.Resources>

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="100"/>
                            <ColumnDefinition Width="80"/>
                            <ColumnDefinition Width="70"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="50"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <TextBlock Text="Von" Grid.Column="1" FontWeight="Heavy" Margin="10,0,0,0"/>
                        <TextBlock Text="Bis" Grid.Column="2" FontWeight="Heavy" Margin="10,0,0,0"/>
                        <TextBlock Text="Total" Grid.Column="3" FontWeight="Heavy" Margin="0"/>
                        <TextBlock Text="Zeit von Team" Grid.Column="4" FontWeight="Heavy"/>
                        <!--<Button HorizontalAlignment="Left" Grid.Column="4" Style="{StaticResource TransparentButtonStyle}" Margin="30,0,0,0" Cursor="Hand" Command="{Binding AddBereichCommand}" ToolTip="{x:Static p:Resources.NeueDienstZeit}">
                            <Path Data="M 0,5 L 10,5 M 5,0 L 5,10" StrokeThickness="3" Stroke="Green" Style="{StaticResource ButtonPathStyle}" />
                        </Button>-->
                        <Button HorizontalAlignment="Left" Grid.Column="6" Margin="30,0,0,0" Cursor="Hand" Command="{Binding AddBereichCommand}" ToolTip="{x:Static p:Resources.NeueDienstZeit}">
                            <TextBlock Text="{x:Static p:Resources.AddNewTime}"/>
                        </Button>
                        
                        <Border BorderBrush="Black" BorderThickness="0,1,0,0" Background="Transparent" Grid.Row="1" Grid.ColumnSpan="7" Margin="0,5,0,0">
                            <ItemsControl ItemsSource="{Binding DienstZeiten}" Margin="0,10,0,0"/>
                        </Border>
                        <!--<ItemsControl ItemsSource="{Binding DienstZeiten}" Grid.Row="1" Grid.ColumnSpan="5" Margin="0,10,0,0" />-->

                    </Grid>
                    
                    <!--<DataGrid ItemsSource="{Binding DienstZeiten}"
                              CanUserAddRows="False"
                              CanUserDeleteRows="False"
                              CanUserReorderColumns="False"
                              CanUserSortColumns="False"
                              AutoGenerateColumns="False">
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding DatumVon}" IsReadOnly="True" Header="Datum von"/>
                            <DataGridTextColumn Binding="{Binding DatumBis}" IsReadOnly="True" Header="bis"/>
                            <DataGridTextColumn Binding="{Binding Von}" IsReadOnly="True" Header="Zeit von"/>
                            <DataGridTextColumn Binding="{Binding Bis}" IsReadOnly="True" Header="bis"/>
                            <DataGridCheckBoxColumn Binding="{Binding IsAbteilungsZeit}" IsReadOnly="True" Header="Zeit von Abteilung"/>
                            <DataGridTextColumn Binding="{Binding ZeitEinheitTyp}" IsReadOnly="True" Header="Typ"/>
                        </DataGrid.Columns>
                    </DataGrid>-->
                    <!--<Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        
                        <TextBlock Text="Datum von"/>
                        <TextBlock Text="bis" Grid.Column="1"/>
                        <TextBlock Text="Zeit von" Grid.Column="2"/>
                        <TextBlock Text="bis" Grid.Column="3"/>
                        <TextBlock Text="Zeit von Abteilung" Grid.Column="4"/>
                        
                    </Grid>-->
                </GroupBox>

            </Grid>
        </GroupBox>

        <StackPanel Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,40,20">
            <Button MinWidth="60" Margin="5" 
                    Command="{Binding DeleteCommand}">
                <TextBlock Text="Löschen"/>
            </Button>
            <Button MinWidth="60" Margin="5" 
                    Command="{Binding NewCommand}">
                <TextBlock Text="Neu"/>
            </Button>
            <Button MinWidth="60" Margin="5"
                    Command="{Binding SaveCommand}">
                <TextBlock Text="Speichern"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsDefault="True" 
                    Command="{Binding OkCommand}">
                <TextBlock Text="OK"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsCancel="True" 
                    Command="{Binding CancelCommand}">
                <TextBlock Text="Abbrechen"/>
            </Button>
        </StackPanel>

    </Grid>
</c:BaseControl>
